<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionController::RecordIdentifier</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionController::RecordIdentifier</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/actionpack/lib/action_controller/record_identifier_rb.html">
                vendor/rails/actionpack/lib/action_controller/record_identifier.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
The record identifier encapsulates a number of naming conventions for
dealing with records, like Active Records or Active <a
href="Resources.html">Resources</a> or pretty much any other model type
that has an id. These patterns are then used to try elevate the view
actions to a higher logical level. Example:
</p>
<pre>
  # routes
  map.resources :posts

  # view
  &lt;% div_for(post) do %&gt;     &lt;div id=&quot;post_45&quot; class=&quot;post&quot;&gt;
    &lt;%= post.body %&gt;           What a wonderful world!
  &lt;% end %&gt;                  &lt;/div&gt;

  # controller
  def destroy
    post = Post.find(params[:id])
    post.destroy

    respond_to do |format|
      format.html { redirect_to(post) } # Calls polymorphic_url(post) which in turn calls post_url(post)
      format.js do
        # Calls: new Effect.fade('post_45');
        render(:update) { |page| page[post].visual_effect(:fade) }
      end
    end
  end
</pre>
<p>
As the example above shows, you can stop caring to a large extent what the
actual id of the post is. You just know that one is being assigned and that
the subsequent calls in redirect_to and the RJS expect that same naming
convention and allows you to write less code if you follow it.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000893">dom_class</a>&nbsp;&nbsp;
      <a href="#M000894">dom_id</a>&nbsp;&nbsp;
      <a href="#M000892">partial_path</a>&nbsp;&nbsp;
      <a href="#M000895">plural_class_name</a>&nbsp;&nbsp;
      <a href="#M000896">singular_class_name</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">JOIN</td>
          <td>=</td>
          <td class="context-item-value">'_'.freeze</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">NEW</td>
          <td>=</td>
          <td class="context-item-value">'new'.freeze</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000893" class="method-detail">
        <a name="M000893"></a>

        <div class="method-heading">
          <a href="#M000893" class="method-signature">
          <span class="method-name">dom_class</span><span class="method-args">(record_or_class, prefix = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The DOM class convention is to use the singular form of an object or class.
Examples:
</p>
<pre>
  dom_class(post)   # =&gt; &quot;post&quot;
  dom_class(Person) # =&gt; &quot;person&quot;
</pre>
<p>
If you need to address multiple instances of the same class in the same
view, you can prefix the <a
href="RecordIdentifier.html#M000893">dom_class</a>:
</p>
<pre>
  dom_class(post, :edit)   # =&gt; &quot;edit_post&quot;
  dom_class(Person, :edit) # =&gt; &quot;edit_person&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000893-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000893-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/record_identifier.rb, line 61</span>
61:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dom_class</span>(<span class="ruby-identifier">record_or_class</span>, <span class="ruby-identifier">prefix</span> = <span class="ruby-keyword kw">nil</span>)
62:       <span class="ruby-identifier">singular</span> = <span class="ruby-identifier">singular_class_name</span>(<span class="ruby-identifier">record_or_class</span>)
63:       <span class="ruby-identifier">prefix</span> <span class="ruby-value">? </span><span class="ruby-node">&quot;#{prefix}#{JOIN}#{singular}&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">singular</span>
64:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000894" class="method-detail">
        <a name="M000894"></a>

        <div class="method-heading">
          <a href="#M000894" class="method-signature">
          <span class="method-name">dom_id</span><span class="method-args">(record, prefix = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
The DOM id convention is to use the singular form of an object or class
with the id following an underscore. If no id is found, prefix with
&quot;new_&quot; instead. Examples:
</p>
<pre>
  dom_id(Post.find(45))       # =&gt; &quot;post_45&quot;
  dom_id(Post.new)            # =&gt; &quot;new_post&quot;
</pre>
<p>
If you need to address multiple instances of the same class in the same
view, you can prefix the <a
href="RecordIdentifier.html#M000894">dom_id</a>:
</p>
<pre>
  dom_id(Post.find(45), :edit) # =&gt; &quot;edit_post_45&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000894-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000894-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/record_identifier.rb, line 75</span>
75:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dom_id</span>(<span class="ruby-identifier">record</span>, <span class="ruby-identifier">prefix</span> = <span class="ruby-keyword kw">nil</span>) 
76:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">record_id</span> = <span class="ruby-identifier">record</span>.<span class="ruby-identifier">id</span>
77:         <span class="ruby-node">&quot;#{dom_class(record, prefix)}#{JOIN}#{record_id}&quot;</span>
78:       <span class="ruby-keyword kw">else</span>
79:         <span class="ruby-identifier">dom_class</span>(<span class="ruby-identifier">record</span>, <span class="ruby-identifier">prefix</span> <span class="ruby-operator">||</span> <span class="ruby-constant">NEW</span>)
80:       <span class="ruby-keyword kw">end</span>
81:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000892" class="method-detail">
        <a name="M000892"></a>

        <div class="method-heading">
          <a href="#M000892" class="method-signature">
          <span class="method-name">partial_path</span><span class="method-args">(record_or_class, controller_path = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns plural/singular for a record or class. Example:
</p>
<pre>
  partial_path(post)                   # =&gt; &quot;posts/post&quot;
  partial_path(Person)                 # =&gt; &quot;people/person&quot;
  partial_path(Person, &quot;admin/games&quot;)  # =&gt; &quot;admin/people/person&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000892-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000892-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/record_identifier.rb, line 42</span>
42:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">partial_path</span>(<span class="ruby-identifier">record_or_class</span>, <span class="ruby-identifier">controller_path</span> = <span class="ruby-keyword kw">nil</span>)
43:       <span class="ruby-identifier">name</span> = <span class="ruby-identifier">model_name_from_record_or_class</span>(<span class="ruby-identifier">record_or_class</span>)
44: 
45:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">controller_path</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">controller_path</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">&quot;/&quot;</span>)
46:         <span class="ruby-node">&quot;#{File.dirname(controller_path)}/#{name.partial_path}&quot;</span>
47:       <span class="ruby-keyword kw">else</span>
48:         <span class="ruby-identifier">name</span>.<span class="ruby-identifier">partial_path</span>
49:       <span class="ruby-keyword kw">end</span>
50:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000895" class="method-detail">
        <a name="M000895"></a>

        <div class="method-heading">
          <a href="#M000895" class="method-signature">
          <span class="method-name">plural_class_name</span><span class="method-args">(record_or_class)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the plural class name of a record or class. Examples:
</p>
<pre>
  plural_class_name(post)             # =&gt; &quot;posts&quot;
  plural_class_name(Highrise::Person) # =&gt; &quot;highrise_people&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000895-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000895-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/record_identifier.rb, line 87</span>
87:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">plural_class_name</span>(<span class="ruby-identifier">record_or_class</span>)
88:       <span class="ruby-identifier">model_name_from_record_or_class</span>(<span class="ruby-identifier">record_or_class</span>).<span class="ruby-identifier">plural</span>
89:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000896" class="method-detail">
        <a name="M000896"></a>

        <div class="method-heading">
          <a href="#M000896" class="method-signature">
          <span class="method-name">singular_class_name</span><span class="method-args">(record_or_class)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the singular class name of a record or class. Examples:
</p>
<pre>
  singular_class_name(post)             # =&gt; &quot;post&quot;
  singular_class_name(Highrise::Person) # =&gt; &quot;highrise_person&quot;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000896-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000896-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_controller/record_identifier.rb, line 95</span>
95:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">singular_class_name</span>(<span class="ruby-identifier">record_or_class</span>)
96:       <span class="ruby-identifier">model_name_from_record_or_class</span>(<span class="ruby-identifier">record_or_class</span>).<span class="ruby-identifier">singular</span>
97:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>